Xbasic

SQL::ConnectionExecute Method

Syntax

Result_Flag as L = Execute(SQLStatement as C [, Arguments as SQL::Arguments [, EventScript as C [, ReferenceTableInfo as SQL::TableInfo [, GetRowCount as L]]]])

Arguments

SQLStatementCharacter

A SQL SELECT statement.

ArgumentsSQL::Arguments

Default = null_value(). A SQL::Arguments object. One or more arguments to be resolved when the SELECT statement is executed.

EventScriptCharacter

Default = "". One or more event scripts. See SQL Events.

ReferenceTableInfoSQL::TableInfo

Default = null_value(). An optional SQL::TableInfo object.

GetRowCountLogical

If .t. (true), gets the row count for the SQL query.

Returns

Result_FlagLogical

TRUE (.T.) if the operation was successful; otherwise FALSE (.F.).

Description

Execute a SQL statement on the connection.

To execute more than one command in a single call, separate each query with a single line containing only '\' at the beginning.

The execute() method executes a query on the connection using SQL. This query can be any valid syntax accepted by the database to which you are connected.

Example

This script prompts for a value, then returns a filtered list of records.

dim conn as SQL::Connection
dim sql as C
dim vCity as C
dim args as SQL::Arguments
vCity = ui_get_text("City", "Show Companies in what city?")
sql = "select lastname, firstname from customer where bill_city = :city Order By Company"
if .not. conn.open("{A5API=Access, FileName='C:\Program Files\a5v8\MDBFiles\Alphasports.mdb', UserName='Admin'}")
    ui_msg_box("Error", conn.CallResult.text)
    end
end if
if .not. args.Add("city", vCity)
    end
end if
if .not. conn.execute(sql, args)
    ui_msg_box("Error", conn.CallResult.text)
    end
end if
sql_resultset_preview(conn.resultset)
conn.close()

Update and Delete Operations

When you execute a SQL UPDATE or DELETE operation, if the WHERE clause does not find any records to operate on, the SQL::Connection.execute() method returns .F. by default.

In some cases, it may be desirable for the SQL::Connection.execute() method to return .T. and treat the "no records found" condition as a warning and not an error. The SQL::Connection.callResult.rowsAffected property can be checked to see if any work was actually done.

To change the default behavior so that the "no records found" condition is a warning, you can either 1) manually update the connection string to add this property to the connection string:

A5ReportNotFoundAsWarning=Y

This property is not exposed in the connection string builder.

or 2) set a property on the connection object. For example:

dim cn as SQL::Connection
cn.ReportNotFoundAsWarning = .t.

See Also